home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 220 / 220.xpi / chrome / flashgot.jar / content / flashgot / SMUninstaller.js < prev    next >
Encoding:
JavaScript  |  2010-01-24  |  4.9 KB  |  141 lines

  1. /***** BEGIN LICENSE BLOCK *****
  2.  
  3.     FlashGot - a Firefox extension for external download managers integration
  4.     Copyright (C) 2004-2009 Giorgio Maone - g.maone@informaction.com
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.                              
  20. ***** END LICENSE BLOCK *****/
  21.  
  22. var SMUninstaller = {
  23.   log: function(msg) {
  24.     dump("[" + EXTENSION_NAME + "] " + msg + "\n");
  25.   },
  26.   
  27.   check: function() {
  28.     this._uninstall("UChrm", EXTENSION_NAME + " Installation",
  29.       EXTENSION_NAME + " detected a previous installation inside your profile and removed it.\n" +
  30.       "SeaMonkey is being closed again to complete the installation process.\n" +
  31.       EXTENSION_NAME +  " will be available as soon as you restart SeaMonkey.");
  32.   },
  33.   
  34.   prompter: CC["@mozilla.org/embedcomp/prompt-service;1"
  35.             ].getService(CI.nsIPromptService),
  36.   
  37.   appUninstall: function(window) {
  38.     if (this.prompter.confirm(window, "Uninstalling " + EXTENSION_NAME,
  39.       "Are you sure you want to uninstall " + EXTENSION_NAME +
  40.       "?\n(SeaMonkey will need to be closed)")) {
  41.       this._uninstall("AChrom", EXTENSION_NAME + " Uninstalled", "SeaMonkey is about to be closed.\nWhen you restart it, " +
  42.                      EXTENSION_NAME + " will be gone.");
  43.       if (window) window.close();
  44.     }
  45.   },
  46.   
  47.   _uninstall: function(dir, title, message) {
  48.     
  49.     try {
  50.       var pChrome = CC["@mozilla.org/file/directory_service;1"].getService(CI.nsIProperties).get(dir, CI.nsIFile).clone();
  51.       
  52.       pChrome.append("chrome.rdf");
  53.       var chromeReg = IO.readFile(pChrome);
  54.       
  55.       var dirty = new RegExp('<RDF:Description RDF:about="urn:mozilla:package:' + CHROME_NAME + '"[^>]*c:extension="true"').test(chromeReg);
  56.       if (!dirty) return;
  57.       var rx = new RegExp('<RDF:Description RDF:about="urn:mozilla:[^"]+:' + CHROME_NAME +
  58.           '"[\\s\\S]*?</RDF:Description>|<RDF:li RDF:resource="urn:mozilla:[^"]+:' + CHROME_NAME + '"/>',
  59.         'g');
  60.       this.log("Removing " + rx.source + " in " + pChrome.path);
  61.       chromeReg = chromeReg.replace(rx, '');
  62.     } catch(e) {
  63.       this.log(e);
  64.     }
  65.     
  66.     
  67.     var self = this;
  68.  
  69.     CC['@mozilla.org/observer-service;1'].getService(CI.nsIObserverService)
  70.         .notifyObservers(CC["@mozilla.org/chrome/chrome-registry;1"]
  71.                        .getService(CI.nsIChromeRegistrySea),
  72.                        "chrome-flush-caches", null);
  73.  
  74.     singleton.delayExec(function() {
  75.       try {
  76.        
  77.         var appStartup = CC["@mozilla.org/toolkit/app-startup;1"].getService(CI.nsIAppStartup);
  78.         
  79.          
  80.         self.log("Patching the chrome registry");
  81.         IO.writeFile(pChrome, chromeReg);
  82.         
  83.         var rx = new RegExp('<RDF:li>chrome://' + CHROME_NAME + '/[^<]+</RDF:li>', 'g');
  84.         
  85.         ["overlays", "stylesheets"].forEach(function(f) {
  86.           try {
  87.             var cf  = pChrome.parent;
  88.             cf.append(f + ".rdf");
  89.             if (cf.exists()) {
  90.               var content = IO.readFile(cf);
  91.               self.log("Removing " + rx.source + " in " + cf.path);
  92.               var patched = content.replace(rx, '');
  93.               if (content != patched) {
  94.                  self.log("Writing " + patched);
  95.                 IO.writeFile(cf, patched);
  96.               }
  97.             }
  98.           } catch(e) {
  99.             self.log("Error patching " + f + ": " + e);
  100.           }
  101.         });
  102.         
  103.         try {
  104.           var jar = pChrome.parent;
  105.           jar.append(CHROME_NAME + ".jar");
  106.           jar.remove(false);
  107.         } catch(e) {}
  108.         
  109.         try {
  110.           var cmp = pChrome.parent.parent;
  111.           cmp.append("components");
  112.           cmp.append(CHROME_NAME + "Service.js");
  113.           cmp.remove(false);
  114.         } catch(e) {}
  115.         
  116.         
  117.         
  118.         var offline = IOS.offline;
  119.         IOS.offline = true;
  120.         
  121.         var window = DOM.mostRecentBrowserWindow;
  122.         self.prompter.alert(
  123.             window, title, message
  124.           );
  125.         
  126.        
  127.         
  128.         self.log("Quit");
  129.         
  130.         IOS.offline = offline;
  131.         
  132.         appStartup.quit(appStartup.eForceQuit);
  133.         
  134.       } catch(e) {
  135.         self.log(e);
  136.       }
  137.     
  138.     }, 10);
  139.   }
  140. }
  141. singleton.smUninstaller = SMUninstaller;